<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>出现最多的字符</title>
</head>
<body>
    <script>
        function getNum(str){
            let obj={}
            for(let i=0;i<str.length;i++){
                obj[str.charAt(i)] ? obj[str.charAt(i)]++ : obj[str.charAt(i)]=1//如果存在就++，不存在就=1
            }
            // console.log(obj)
            let num=0,quan=''
            for(var key in obj){
                if(obj[key]>num){//循环对象如果有比num大的就赋值
                    num=obj[key]
                    quan=key
                }
            }
            console.log(quan+':'+num)
        }
        let str='cbbaajjjbdaaa'
        getNum(str)
    </script>
</body>
</html>